/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ivanhoe
 */
@Entity
@Table(name = "ventas")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ventas.findAll", query = "SELECT v FROM Ventas v"),
    @NamedQuery(name = "Ventas.findByIdVenta", query = "SELECT v FROM Ventas v WHERE v.idVenta = :idVenta")})
public class Ventas implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "id_venta")
    private Integer idVenta;
    @JoinTable(name = "ventas_has_clientes", joinColumns = {
        @JoinColumn(name = "ventas_id_venta", referencedColumnName = "id_venta")}, inverseJoinColumns = {
        @JoinColumn(name = "clientes_id_cliente", referencedColumnName = "id_cliente")})
    @ManyToMany
    private Collection<Clientes> clientesCollection;
    @JoinTable(name = "ventas_has_cotizacion", joinColumns = {
        @JoinColumn(name = "ventas_id_venta", referencedColumnName = "id_venta")}, inverseJoinColumns = {
        @JoinColumn(name = "cotizacion_id_cotizacion", referencedColumnName = "id_cotizacion")})
    @ManyToMany
    private Collection<Cotizacion> cotizacionCollection;
    @JoinTable(name = "ventas_has_ordenes_trabajo", joinColumns = {
        @JoinColumn(name = "ventas_id_venta", referencedColumnName = "id_venta")}, inverseJoinColumns = {
        @JoinColumn(name = "ordenes_trabajo_id_orden_trabajo", referencedColumnName = "id_orden_trabajo")})
    @ManyToMany
    private Collection<OrdenesTrabajo> ordenesTrabajoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "ventasIdVenta")
    private Collection<DetalleVenta> detalleVentaCollection;
    @JoinColumn(name = "id_estado_venta", referencedColumnName = "id_estado_venta")
    @ManyToOne(optional = false)
    private EstadoVenta idEstadoVenta;
    @JoinColumn(name = "id_tipo_venta", referencedColumnName = "id_tipo_venta")
    @ManyToOne(optional = false)
    private TiposVenta idTipoVenta;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "ventas")
    private Collection<VentasHasEstadoVenta> ventasHasEstadoVentaCollection;

    public Ventas() {
    }

    public Ventas(Integer idVenta) {
        this.idVenta = idVenta;
    }

    public Integer getIdVenta() {
        return idVenta;
    }

    public void setIdVenta(Integer idVenta) {
        this.idVenta = idVenta;
    }

    @XmlTransient
    public Collection<Clientes> getClientesCollection() {
        return clientesCollection;
    }

    public void setClientesCollection(Collection<Clientes> clientesCollection) {
        this.clientesCollection = clientesCollection;
    }

    @XmlTransient
    public Collection<Cotizacion> getCotizacionCollection() {
        return cotizacionCollection;
    }

    public void setCotizacionCollection(Collection<Cotizacion> cotizacionCollection) {
        this.cotizacionCollection = cotizacionCollection;
    }

    @XmlTransient
    public Collection<OrdenesTrabajo> getOrdenesTrabajoCollection() {
        return ordenesTrabajoCollection;
    }

    public void setOrdenesTrabajoCollection(Collection<OrdenesTrabajo> ordenesTrabajoCollection) {
        this.ordenesTrabajoCollection = ordenesTrabajoCollection;
    }

    @XmlTransient
    public Collection<DetalleVenta> getDetalleVentaCollection() {
        return detalleVentaCollection;
    }

    public void setDetalleVentaCollection(Collection<DetalleVenta> detalleVentaCollection) {
        this.detalleVentaCollection = detalleVentaCollection;
    }

    public EstadoVenta getIdEstadoVenta() {
        return idEstadoVenta;
    }

    public void setIdEstadoVenta(EstadoVenta idEstadoVenta) {
        this.idEstadoVenta = idEstadoVenta;
    }

    public TiposVenta getIdTipoVenta() {
        return idTipoVenta;
    }

    public void setIdTipoVenta(TiposVenta idTipoVenta) {
        this.idTipoVenta = idTipoVenta;
    }

    @XmlTransient
    public Collection<VentasHasEstadoVenta> getVentasHasEstadoVentaCollection() {
        return ventasHasEstadoVentaCollection;
    }

    public void setVentasHasEstadoVentaCollection(Collection<VentasHasEstadoVenta> ventasHasEstadoVentaCollection) {
        this.ventasHasEstadoVentaCollection = ventasHasEstadoVentaCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idVenta != null ? idVenta.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ventas)) {
            return false;
        }
        Ventas other = (Ventas) object;
        if ((this.idVenta == null && other.idVenta != null) || (this.idVenta != null && !this.idVenta.equals(other.idVenta))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Ventas[ idVenta=" + idVenta + " ]";
    }
    
}
